package io.gitee.zhangbinhub.acp.boot.warm.flow.integration

import com.mybatisflex.core.FlexGlobalConfig
import com.mybatisflex.core.MybatisFlexBootstrap
import io.gitee.zhangbinhub.acp.boot.warm.flow.conf.WarmFlowAutoConfig
import org.dromara.warm.flow.orm.mapper.*
import org.dromara.warm.plugin.modes.solon.config.BeanConfig
import org.noear.solon.core.AppContext
import org.noear.solon.core.Plugin
import org.noear.solon.core.event.EventBus


class XPluginImp : Plugin {
    override fun start(context: AppContext) {
        context.beanMake(BeanConfig::class.java)
        context.beanMake(WarmFlowAutoConfig::class.java)
        EventBus.subscribe(FlexGlobalConfig::class.java) { flexGlobalConfig ->
            flexGlobalConfig.configuration.addMapper(FlowDefinitionMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowFormMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowHisTaskMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowInstanceMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowNodeMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowSkipMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowTaskMapper::class.java)
            flexGlobalConfig.configuration.addMapper(FlowUserMapper::class.java)
        }
        context.lifecycle {
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowDefinitionMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowFormMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowHisTaskMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowInstanceMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowNodeMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowSkipMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowTaskMapper::class.java))
            context.beanInject(MybatisFlexBootstrap.getInstance().getMapper(FlowUserMapper::class.java))
        }
    }
}